package com.rao.gmall.search.api;

import com.rao.gmall.common.result.Result;
import com.rao.gmall.model.list.Goods;
import com.rao.gmall.model.list.SearchParam;
import com.rao.gmall.model.list.SearchResponseVo;
import com.rao.gmall.search.service.SkuEsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author nzmxfan
 * @create 2021-08-13-19:57
 */
@RestController
@RequestMapping("/es/sku/inner")
public class SkuEsController {

    @Autowired
    SkuEsService skuEsService;

    /**
     *  es 中上架商品
     * @param goods
     * @return
     */
    @PostMapping("/onSale")
    public Result onSale(@RequestBody Goods goods){

        skuEsService.save(goods);

        return Result.ok();
    }

    /**
     * es 中下架商品
     * @param skuId
     * @return
     */
    @PostMapping("/cancelSale/{skuId}")
    public Result deleteById(@PathVariable("skuId") Long skuId){
        skuEsService.deleteById(skuId);
        return  Result.ok();
    }

    @PostMapping("/search")
    public SearchResponseVo searchGood(@RequestBody SearchParam searchParam){
        SearchResponseVo searchResponseVo = skuEsService.search(searchParam);
        return searchResponseVo;
    }

    @GetMapping("/hotScore/{skuId}")
    public Result updateSkuHotScore(@PathVariable("skuId") Long skuId,
                             @RequestParam("hotScore") Long hotScore){
        skuEsService.updateSkuHotScore(skuId, hotScore);
        return Result.ok();
    }
}
